package com.szcinda.fitness.controller;

import com.szcinda.fitness.TrainService;
import com.szcinda.fitness.controller.utils.Result;
import com.szcinda.fitness.dto.DailyTrainDto;
import com.szcinda.fitness.dto.QueryDailyTrainParams;
import com.szcinda.fitness.dto.SaveTrainDto;
import com.szcinda.fitness.dto.TrainPlanDto;
import com.szcinda.fitness.persistence.TrainPlan;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/train")
public class TrainController {

    private final TrainService trainService;

    public TrainController(TrainService trainService) {
        this.trainService = trainService;
    }

    @PostMapping("/dailyTrain")
    public Result<DailyTrainDto> dailyTrain(@RequestBody QueryDailyTrainParams params) {
        return Result.success(trainService.getDailyTrain(params.getOpenId(), params.getTrainDate()));
    }

    @GetMapping("trainDayList/{openId}")
    public Result<List<String>> trainDayList(@PathVariable String openId) {
        return Result.success(trainService.trainDayList(openId));
    }


    @GetMapping("trainPlan/{openId}")
    public Result<TrainPlanDto> trainPlan(@PathVariable String openId) {
        return Result.success(trainService.getTrainPlan(openId));
    }

    @PostMapping("savePlan")
    public Result savePlan(@RequestBody TrainPlan trainPlan) {
        trainService.saveTrainPlan(trainPlan);
        return Result.success();
    }

    @PostMapping("saveNote")
    public Result saveNote(@RequestBody SaveTrainDto saveTrainDto){
        trainService.saveNote(saveTrainDto.getOpenId(), saveTrainDto.getTrainDate(), saveTrainDto.getTrainNote());
        return Result.success();
    }

    @PostMapping("savePositions")
    public Result savePositions(@RequestBody SaveTrainDto saveTrainDto) {
        trainService.saveTrainPositions(saveTrainDto.getOpenId(), saveTrainDto.getTrainDate(), saveTrainDto.getTrainPositions());
        return Result.success();
    }

    @PostMapping("saveTypes")
    public Result saveTypes(@RequestBody SaveTrainDto saveTrainDto) {
        trainService.saveTrainTypes(saveTrainDto.getOpenId(), saveTrainDto.getTrainDate(), saveTrainDto.getTrainTypes());
        return Result.success();
    }

    @PostMapping("saveMovements")
    public Result saveMovements(@RequestBody SaveTrainDto saveTrainDto) {
        trainService.saveTrainMovements(saveTrainDto.getOpenId(), saveTrainDto.getTrainDate(), saveTrainDto.getTrainMovements());
        return Result.success();
    }

    @PostMapping("saveMeasurements")
    public Result saveMeasurements(@RequestBody SaveTrainDto saveTrainDto) {
        trainService.saveBodyMeasurements(saveTrainDto.getOpenId(), saveTrainDto.getTrainDate(), saveTrainDto.getBodyMeasurements());
        return Result.success();
    }
}
